package com.xuecheng.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.api.content.model.dto.TeachplanMediaDTO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.content.convert.TeachplanMediaConvert;
import com.xuecheng.content.entity.TeachplanMedia;
import com.xuecheng.content.mapper.TeachplanMediaMapper;
import com.xuecheng.content.service.TeachplanMediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Service
public class TeachplanMediaServiceImpl extends ServiceImpl<TeachplanMediaMapper, TeachplanMedia> implements TeachplanMediaService {


    /**
     * <p>
     * 查询课程下媒资绑定信息 远程调用
     * </p>
     *
     * @param mediaId 媒资id
     * @return TeachplanMediaDTO
     */
    @Override
    public RestResponse getByMediaId(Long mediaId) {


        LambdaQueryWrapper<TeachplanMedia> queryWrapper = Wrappers.lambdaQuery(TeachplanMedia.class)
                .eq(TeachplanMedia::getMediaId, mediaId);

        List<TeachplanMedia> list = this.list(queryWrapper);

        List<TeachplanMediaDTO> teachplanMediaDTOS = Collections.emptyList();
        if (CollectionUtils.isNotEmpty(list)) {
            teachplanMediaDTOS = TeachplanMediaConvert.INSTANCE.teachplanMediaToDTOList(list);
        }
        return RestResponse.success(teachplanMediaDTOS);
    }
}
